import wx
import wx.adv
import os
import subprocess

TRAY_ICON = 'computer.png'
TRAY_TOOLTIP = '托盘示例'

# 导入“我的计算机”程序
from pc_info2 import MyFrame  # 假设“我的计算机”程序代码保存在my_computer_module.py文件中

class MonitorTaskBarIcon(wx.adv.TaskBarIcon):
    def __init__(self):
        super().__init__()

        icon = wx.Icon(TRAY_ICON)
        self.SetIcon(icon, TRAY_TOOLTIP)
        self.Bind(wx.adv.EVT_TASKBAR_RIGHT_DOWN, self.OnRightClicked)

    def OnRightClicked(self, event):
        menu = wx.Menu()

        # 添加菜单项
        my_computer_item = menu.Append(wx.ID_ANY, "我的计算机")
        my_ai_item = menu.Append(wx.ID_ANY, "我的AI")
        task_manager_item = menu.Append(wx.ID_ANY, "任务管理器")
        # 新增的三个菜单项
        program1_item = menu.Append(wx.ID_ANY, "程序1")
        program2_item = menu.Append(wx.ID_ANY, "程序2")
        program3_item = menu.Append(wx.ID_ANY, "程序3")
        exit_item = menu.Append(wx.ID_EXIT, "E&xit")

        # 绑定事件
        self.Bind(wx.EVT_MENU, self.OpenMyComputer, my_computer_item)
        self.Bind(wx.EVT_MENU, self.OpenMyAI, my_ai_item)
        self.Bind(wx.EVT_MENU, self.OpenTaskManager, task_manager_item)
        self.Bind(wx.EVT_MENU, self.OnExit, exit_item)

        self.PopupMenu(menu)
        menu.Destroy()

    def OnExit(self, event):
        wx.GetApp().ExitMainLoop()

    def OpenMyComputer(self, event):
        # 创建并显示“我的计算机”窗口
        frame = MyFrame(None)
        frame.Show()

    def OpenMyAI(self, event):
        # 假设你的AI程序的可执行文件路径是 "C:\Program Files\MyAI\MyAI.exe"
        subprocess.run(["C:\\Program Files\\MyAI\\MyAI.exe"])

    def OpenTaskManager(self, event):
        # 打开任务管理器
        os.system("taskmgr.exe")

class MyApp(wx.App):
    def OnInit(self):
        frame = wx.Frame(None, wx.ID_ANY, "TaskBar")
        self.SetTopWindow(frame)
        MonitorTaskBarIcon()
        return True

if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()
